﻿function GoogleLanguageInitializeValue(client_id, dest_lang) {
    var text = document.getElementById(client_id).value;
    google.language.detect(text, function(result) {
        if (!result.error && result.language) {
            google.language.translate(text, result.language, dest_lang,
                function(result) {
                    if (!result.error) {
                        var translated = document.getElementById(client_id);
                        if (result.translation) {
                            translated.value = result.translation;
                        }
                    }
                });
        }
    });
}

function GoogleLanguageInitializeSiblingValue(client_id, dest_lang) {
    if (document.getElementById(client_id).nextSibling != null) {
        var text = document.getElementById(client_id).nextSibling.innerHTML;
        google.language.detect(text, function(result) {
            if (!result.error && result.language) {
                google.language.translate(text, result.language, dest_lang,
                    function(result) {
                        if (!result.error) {
                            var translated = document.getElementById(client_id);
                            if (result.translation) {
                                translated.nextSibling.innerHTML = result.translation;
                            }
                        }
                    });
            }
        });
    }
}